﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using GrayParrot.ServiceBroker;
using GrayParrot.Core.Serialization;
using Test.BLL;

namespace TestServiceBroker
{
    public class TestServiceBrokerSubscriber : Subscriber<TestServiceBrokerSubscriber> 
    {
        public TestServiceBrokerSubscriber()
            : base("feeds")
        {

        }

        public override bool Receive(string message)
        {
            bool retValue = false;

            try
            {
                MessageBusBase<MessaggioTest> msg = message.DeserializeAsXml<MessageBusBase<MessaggioTest>>();

                MessaggioTest obj = msg.Body;

                Console.WriteLine("{0} - {1}", obj.Name, obj.Age);

                Thread.Sleep(100);

                retValue = true;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                retValue = false;
            }

            //throw new Exception("Prova di errore");

            return retValue;
        }
    }
}
